package com.asman.vr.utils

import org.greenrobot.eventbus.EventBus

/**
 * Created by ybk on 2018/2/8.
 */
object EventBusUtils {

    fun post(event: Any) {
        EventBus.getDefault().post(event)
    }

    fun postSticky(event: Any) {
        EventBus.getDefault().postSticky(event)
    }

    fun register(subscriber: Any) {
        if (!isRegister(subscriber)) {
            try {
                EventBus.getDefault().register(subscriber)
            } catch (e: Exception) {
                e.printStackTrace()
            }

        }
    }

    fun unRegister(subscriber: Any) {
        if (isRegister(subscriber)) {
            try {
                EventBus.getDefault().unregister(subscriber)
            } catch (e: Exception) {
                e.printStackTrace()
            }

        }
    }

    private fun isRegister(subscriber: Any): Boolean {
        return EventBus.getDefault().isRegistered(subscriber)
    }
}
